package com.cjlgb.design.common.security.exception;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import lombok.SneakyThrows;

/**
 * @author WFT
 * @date 2019/7/22
 * description:
 */
public class SecurityExceptionSerializer extends StdSerializer<SecurityException> {

    public SecurityExceptionSerializer() {
        super(SecurityException.class);
    }

    @Override
    @SneakyThrows
    public void serialize(SecurityException e, JsonGenerator generator, SerializerProvider provider) {
        generator.writeStartObject();
        generator.writeObjectField("code", e.getHttpErrorCode());
        generator.writeStringField("msg", e.getMessage());
        generator.writeEndObject();
    }
}
